
public class Disc extends Primitive{
	
	private Vector center = null;
	private Vector normal = null;
	private double radius;
	
	public Disc(){
		this.center = new Vector();
		this.normal = new Vector();
		this.radius = 0;
		this.setSurface(new Surface());
	}
	
	public Disc(Vector center, Vector normal, double radius){
		this();
		this.center = center;
		this.normal = normal.normlized();
		this.radius = radius;
	}
	
	public Disc(Vector center, Vector normal, double radius, Surface surface){
		this(center, normal, radius);
		this.setSurface(surface);
	}
	
	public void setCenter(Vector center) {
		this.center = center;
	}
	
	public Vector getCenter(){
		return center;
	
	}
	
	public void setNormal(Vector normal) {
		this.normal = normal;
	}
	
	public Vector getNormal(){
		return normal;
	}
	
	public void setRadius(double radius){
		this.radius = radius;
	}
	
	public double getRadius(){
		return radius;
	}
	
	@Override
	public Vector intersectionPoint_direction(Vector source, Vector direction ){
		if(Vector.dotProduct(direction, normal)== 0) { //parallel to plain
			return null; // may want to also check if line is contained in plain
		}
		double Var = (Vector.dotProduct(normal, center) - Vector.dotProduct(normal, source))
					/Vector.dotProduct(normal, direction);
		
		if (Var < 0.0) return null;
		
		Vector intersectionPoint = Vector.add(source, direction.mul(Var));
		
		if ( Vector.getDistance(center, intersectionPoint) <= radius){
			
			return intersectionPoint;
		}
		return null;
	}

	@Override
	public Vector getNormalAt(Vector target, Vector viewDirection) {
		Vector outSide = Vector.add(target, viewDirection.mul(-1));
		if (outSide.isUnderPlain(this.center, this.normal))
			return this.normal.mul(-1);
		return this.normal;
	}
	
	public static Disc getDBGdisc(){
		//Disc dsc = new Disc( new Vector(-2, 2, 1), new Vector(1,0,0), 2);
		Disc dsc = new Disc( new Vector(0, -2.25, 0), new Vector(0,1,0), 10);
		dsc.setMtlDiffuse(new RGB(0.2,0.6,0.5));
		dsc.setMtlAmbient(new RGB(0.2,0.6,0.5));
		return dsc;
	}
	
	public static Disc getDBGdisc2(){
		//Disc dsc = new Disc( new Vector(-2, 2, 1), new Vector(1,0,0), 2);
		Disc dsc = new Disc( new Vector(-2, 1, -2), new Vector(0,1,0), 2);
		dsc.setMtlDiffuse(new RGB(0.2,0.7,0.9));
		return dsc;
	}

	@Override
	public Vector getLowestPoint() {
		double[] c = center.getCoords();
		return new Vector(c[0] - this.radius, c[1] - this.radius , c[2] - this.radius);
	}

	@Override
	public Vector getHighestPoint() {
		double[] c = center.getCoords();
		return new Vector(c[0] + this.radius, c[1] + this.radius , c[2] + this.radius);
	}
	
}
